<style scoped>
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }

  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .rj-cell.note {
    width: 100%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .attachimg {
    /*width: 100%;*/
  }

  .tit label, .tit span {
    font-size: 16px;
  }

  .tit label {
    padding-right: 20px;
  }

  .weui-panel.weui-panel_access {
    padding-bottom: 10px;
  }

  /*.weui-panel__bd:not(.base) {*/
  /*  width: 98%;*/
  /*  padding: 0 1% 2px 1%;*/
  /*}*/

  .rj-cont-tit:not(.base) {
    border-radius: 5px;
  }

  .weui-cell {
    background: #fff;
  }

  .weui-cells__title {
    text-align: left;
    background: #eee;
  }

  .oitem {
    padding: 3px;
  }

  #acts span {
    font-size: 14px;
  }

  .weui-label {
    text-align: left;
  }

  .weui-media-box {
    text-align: left;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui_navbar_item {
    font-size: 14px;
  }
  .weui_navbar_item.weui_bar_item_on {
    color: #3cc51f;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .weui-cells {
    margin-top: 0;
  }
  .rj-wrap {
    background: #eee;
    overflow:auto;overflow-x: hidden
  }
  .rj-cont {
    background: #fff;
  }
  .weui-panel {
    background: #eee;
  }
  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }
  .weui-panel {
    margin-top: 0;
  }
  .demos-content-padded {
    padding: 15px;
  }
  .attachimg {
    width: 100%;
  }
  .tp-item {
    width: 32%;text-align: center;background: #fafafa;
    padding: 5px 2px;
    /*overflow: auto;*/
  }


  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui_navbar_item {
    font-size: 14px;
  }
  .weui_navbar_item.weui_bar_item_on {
    color: #3cc51f;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .list {
    /*padding-bottom: 320px;*/
    overflow: auto;
    background: #eee;
  }
  .rj-cell {
    display: inline-block;
    /*font-size: 0;*/
    padding: 5px 15px;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
  }
  .rj-cell span {
    padding-left: 5px;
    font-size: 14px;
    color: #333;
  }
  .weui-cells {
    border-radius: 5px;
    margin-top: 0;
  }
  .paylayer {
    width: 100%;
    text-align: center;
    /*position: fixed;*/
    bottom: 0;
    border-top: 1px solid #ddd;
    background: #fff;
    z-index: 100;
  }
  .rj-wrap {
    background: #eee;
    overflow:auto;overflow-x: hidden
  }
  .rj-cont {
    background: #fff;
  }
  .rj-cell span i {
    color: red;
    font-size: 30px;
    font-style: normal;
  }
  .paylayer .rj-cell {
    padding: 5px;
  }
  .weui-panel {
    background: #eee;
  }
  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }
  .weui-panel {
    margin-top: 0;
  }
  .all-btn {
    position: absolute;
    right: 8px;
    top: 1px;
  }
  .all-btn i {
    font-size: 16px;
    position: absolute;
    left: -7px;
    top: 8px;
  }

  .weui_uploader_input_wrp {
    float: left;
    position: relative;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 77px;
    height: 77px;
    border: 1px solid #D9D9D9;
  }

  .weui_uploader_files {
    list-style: none;
  }

  .weui_uploader_input_wrp:before {
    width: 2px;
    height: 39.5px;
  }

  .weui_uploader_input_wrp:before, .weui_uploader_input_wrp:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background-color: #D9D9D9;
  }

  .weui_uploader_input {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }

  .weui_uploader_input_wrp:after {
    width: 39.5px;
    height: 2px;
  }

  .weui_uploader_bd {
    overflow: hidden;
  }
  .outstore >>> .weui-uploader_file {
    float: left;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 79px;
    background: no-repeat 50%;
    background-size: cover;
  }

  .weui-cell.fir {
    border-top: 0;
  }
  .weui_uploader_input_wrp.inrow {
    width: 30px;
    height: 30px;
    margin: 0;
  }

  .weui_uploader_input_wrp:before {
    height: 19.5px;
  }

  .weui_uploader_input_wrp:after {
    width: 19.5px;
  }

  .weui-uploader_file.inrow {
    margin: 0;
    width: 40px;
  }

  li.weui-uploader_file {
    display: inline-block;
    padding: 3px 5px;
  }

  ul#images {
    text-align: right;
  }
  .uploadtit {
    width: 30%;
    float: left;
    text-align: left;
    padding-top: 4px;
  }
</style>
<template>
<!--  <div class="comon" style="background: #eee;height: 100%;">-->
  <div class="comon" style="background: #eee;height: 100%;overflow: auto;">
    <div
      style="height: 50px; line-height: 50px; background: #fff; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      采购订单列表
      <a href="javascript:" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <div class="weui-panel weui-panel_access">
      <div class="weui-panel__bd">
        <div class="weui-form-preview billitem rj-cont-tit" style="position: relative;">
          <div class="rj-cell max">
            <span style="width: 100%;">{{supplier.name}}</span>
<!--            <span style="width: 100%;">{{supplier.name}}</span>-->
<!--            <span style="width: 100%;">{{supplier.contactstel}}</span>-->
            <span style="width: max-content;max-width: 130px;display: inline-block;text-align: left;">{{supplierName}}</span>
          </div>
          <div class="rj-cell all-btn" style="" id="allSec" @click="selectAll">
            <i :class="selected ? 'weui-icon-circle' : 'weui-icon-success'"></i>
            <label>全选</label>
          </div>
        </div>
        <div class="weui-form-preview billitem rj-cont-tit" style="position: relative;">
<!--          <div class="rj-cell max">-->
<!--            <div class="weui-cell rj-cont" style="background: #fff;padding: 0;">-->
<!--              <div class="weui-cell__hd"><label class="weui-label" style="font-weight: 600;padding-left: 5px;">采收合同</label></div>-->
<!--              <div class="weui-cell__bd">-->
<!--&lt;!&ndash;                <input class="weui-input select" name="contract" id="contract" type="text" placeholder="请选择采收合同" style="font-size: 14px;" readonly="">&ndash;&gt;-->
<!--                <select class="weui-select" v-model="ctract" @change="val => {bank = val.bank; bankcode = val.bankcode}">-->
<!--                  <option value="" disabled>请选择采收合同</option>-->
<!--                  <option v-for="(item, index) in ctracts" :key="item.id" :value="item">-->
<!--                    {{ item.name }}-->
<!--                  </option>-->
<!--                </select>-->
<!--              </div>-->
<!--            </div>-->
<!--          </div>-->
          <div class="rj-cell max">
            <div class="weui-cell rj-cont" style="background: #fff;padding: 0;min-width: 350px;">
              <div class="weui-cell__hd"><label class="weui-label" style="font-weight: 600;padding-left: 5px;width: 80px;">开户行</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input select" name="bank" type="text" id="bank" v-model="bank" placeholder="请输入开户行" style="font-size: 14px;">
              </div>
            </div>
          </div>
          <div class="rj-cell max">
            <div class="weui-cell rj-cont" style="background: #fff;padding: 0;min-width: 350px;">
              <div class="weui-cell__hd"><label class="weui-label" style="font-weight: 600;padding-left: 5px;width: 80px;">银行账号</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input select" name="bankcode" type="text" id="bankcode" v-model="bankcode" placeholder="请输入银行账号" style="font-size: 14px;">
              </div>
            </div>
          </div>
          <!-- <div class="rj-cell all-btn" style="" id="allSec">
              <i class="weui-icon-circle"></i>
              <label>全选</label>
          </div> -->
        </div>

      </div>
    </div>
    <div class="list" id="list">
      <div class="weui-form-preview">
        <div class="weui-cells weui-cells_checkbox">
          <div v-for="(item, index) in forders" class="weui-cell">
            <div class="weui-cell__bd weui-cell_primary payitem" style="text-align: left;" :data-guid="item.guid">
              <p> </p>
              <div class="rj-cell max" style="min-width: 110px;">
                <label></label>
                <span>{{item.code}}</span>
              </div>
              <div class="rj-cell" style="min-width: 110px;">
                <label>数量：</label>
                <span>{{item.totalnum}}</span>
              </div>
              <div class="rj-cell" style="min-width: 110px;">
                <label>金额：</label>
                <span>{{item.totalamount}} 元</span>
              </div>
              <div class="rj-cell" style="min-width: 110px;">
                <label>采购日期：</label>
                <span>{{item.purchdate}}</span>
              </div>
              <p></p>
            </div>
            <label class="weui-check_label weui-cell__ft" :for="'weui-select-id-' + item.id">
              <input type="checkbox" class="weui-check order" name="weui-select" v-model="forderIds['order' + index]" @change="huizong(item.settlement, item.weight, item.guid)" :data-amount="item.totalamount" :data-weight="item.totalnum" :data-guid="item.guid" :id="'weui-select-id-' + item.id" :ref="'order' + index" :value="item.id" data-title="">
              <span class="weui-icon-checked"></span>
            </label>
          </div>
        </div>
      </div>
    </div>
    <div class="weui-loadmore" style="display: none;" id="dis">
      <i class="weui-loading"></i>
      <span class="weui-loadmore__tips">正在加载</span>
    </div>
<!--    <div class="weui-loadmore weui-loadmore_line" style="" id="disp">-->
<!--      <span class="weui-loadmore__tips">没有更多了</span>-->
<!--    </div>-->
    <div class="paylayer">
      <div class="rj-cell">
        <label>合计：</label>
      </div>
      <div class="rj-cell">
        <label></label>
        <span id="carnum"><i>{{carnum}}</i> 订单</span>
      </div>
      <div class="rj-cell">
        <label>数量:</label>
        <span id="weight"><i>{{weight}}</i> </span>
      </div>
      <div class="rj-cell">
        <label></label>
        <span id="amount"><i>{{amount}}</i> 元</span>
      </div>
      <div class="weui-cell">
<!--        <div class="weui-cell__hd"><label class="weui-label" style="text-align: left;">申请金额</label></div>-->
        <div class="weui-cell__bd" style="display: flex">
          <div style="display: inline-block;width: 50%;">
            <input style="display: inline-block;width: 70%;color: red;" class="weui-input" type="number" id="payAmount" placeholder="请输入支付金额" v-model="payAmount" @change="takePayAmount">
            <input style="display: inline-block;width: 20%;" class="weui-input" readonly="" value="元">
          </div>
          <div style="display: inline-block;width: 50%;">
            <input style="display: inline-block;width: 70%;" class="weui-input" type="number" id="payRate" v-model="payRate" @change="takePayRate" placeholder="请输入支付比例">
            <input style="display: inline-block;width: 20%;" class="weui-input" readonly="" value="%">
          </div>
        </div>
      </div>
<!--      <div class="weui-cell">-->
<!--        <div class="weui-cell__hd"><label class="weui-label" style="text-align: left;">申请比例</label></div>-->
<!--        <div class="weui-cell__bd" style="text-align: left;">-->
<!--          <input style="display: inline-block;width: 30%;" class="weui-input" type="number" id="payRate" v-model="payRate" @change="takePayRate" placeholder="请输入">-->
<!--          <input style="display: inline-block;width: 60%;" class="weui-input" readonly="" value="%">-->
<!--        </div>-->
<!--      </div>-->
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">附件上传</label></div>
        <div class="weui-cell__ft">
          <div class="weui_uploader_bd">
            <ul class="weui_uploader_files"></ul>
            <div class="weui_uploader_input_wrp inrow">
              <UploadFile3 class="weui_uploader_input" v-on:pushfile="setFile"></UploadFile3>
            </div>
          </div>
        </div>
        <ul class="weui-uploader_files" id="images">
          <li class="weui-uploader_file" v-for="(fil, index) in filenames" @click=delFile(fil,fileids[index])>
            {{fil}}
          </li>
        </ul>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <textarea class="weui-textarea" id="remark" name="remark" v-model="opinion" placeholder="请输入备注" rows="2"></textarea>
        </div>
      </div>
      <div class="weui-form-preview__ft">
        <a class="weui-form-preview__btn weui-form-preview__btn_primary subbtn" @click="postForm()" href="javascript:">提交</a>
        <a class="weui-form-preview__btn weui-form-preview__btn_default" @click="$router.push({path: '/purchase2/bill/pays'})">返回</a>
      </div>
    </div>
  </div>
</template>

<script>
  import UploadFile3 from "@/components/common/UploadFile3";
  export default {
    name: 'AddBill42',
    data() {
      return {
        flowid: 42,
        userid: localStorage.userId,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        filenames: [],
        fileids: [],
        forders: [],
        id: '',
        supplierId: '',
        supplierName: '',
        carnum: 0,
        weight: 0,
        amount: 0,
        forderIds: {},
        selected: false,
        totalGuids: '',
        payAmount: '',
        payRate: '',
        opinion: '',
        bank: '',
        bankcode: '',
        supplier: '',
        orgId: ''
      }
    },
    components: {
      UploadFile3
    },
    created() {
      window.addEventListener('setItem', () => {
        this.userid = localStorage.getItem('userId');
      })
    },
    mounted() {
      this.supplierId = this.$route.query.supplierId;
      this.supplierName = this.$route.query.supplierName;
      this.orgId = this.$route.query.orgId;
      this.id = this.$route.query.id;
      this.getSupplier();
      this.getForders();
    },
    methods: {
      takePayAmount: function() {
        if (!this.totalGuids) {
          this.toastText("请先选择采购订单");
          this.payAmount = '';
          this.payRate = '';
          return false;
        }
        let payRate = this.toFix2((this.payAmount / this.amount)) * 100;
        this.payRate = payRate;
      },
      takePayRate: function() {
        if (!this.totalGuids) {
          this.toastText("请先选择采购订单");
          this.payAmount = '';
          this.payRate = '';
          return false;
        }
        let payAmount = this.toFix2((this.payRate / 100) * this.amount);
        this.payAmount = payAmount;
      },
      //汇总数据
      huizong: function () {
        // var elem = $('input[name="weui-select"]:checked');
        // var len = Object.keys(this.forderIds).filter(item => this.forderIds[item]).length;
        // var elem = elem.length;
        let totalAmoumt = 0;
        let totalCarnum = 0;
        let totalWeight = 0;
        this.totalGuids = "";
        Object.keys(this.forderIds).filter(item => this.forderIds[item]).forEach(item => {
          console.log('item:', item)
          // console.log('this.forderIds[item]:', this.forderIds[item])
          let elem = this.$refs[item][0];
          console.log('elem:', elem)
          totalAmoumt += parseFloat(elem.getAttribute('data-amount'));
          totalWeight += parseFloat(elem.getAttribute('data-weight'));
          this.totalGuids = this.totalGuids + elem.getAttribute('data-guid') + ',';
          totalCarnum += 1;
        })
        //联动全选按钮
        if (totalCarnum == Object.keys(this.forderIds).length) {
          if (this.selected) {
            this.selected = false;
          }
        } else {
          if (!this.selected) {
            this.selected = true;
          }
        }

        this.amount = this.toDecimal2NoZero(totalAmoumt);
        this.weight = this.toDecimal2NoZero(totalWeight);
        this.carnum = totalCarnum;
        // $('#amount i').text(toDecimal2NoZero(totalAmoumt));
        // $('#weight i').text(toDecimal2NoZero(totalWeight));
        // $('#carnum i').text(totalCarnum);
        this.totalGuids = this.totalGuids.substr(0,this.totalGuids.length-1);
      },
      selectAll: function() {
        //为true 则至少一个没选中
        this.selected  = Object.keys(this.forderIds).some(item => !this.forderIds[item]);
        if (this.selected) {
          console.log(1111111111)
          //全部选中
          this.switchChecked(false);
        } else {
          console.log(2222222222)
          //全部不选
          this.switchChecked(true);
        }
      },
      switchChecked: function (status) {
        if (status) {
          //全部不选
          Object.keys(this.forderIds).forEach(item => {
            if (this.forderIds[item]) {
              this.forderIds[item] = false;
            }
          })
          this.selected = true;
        } else {
          //全部选中
          Object.keys(this.forderIds).forEach(item => {
            if (!this.forderIds[item]) {
              this.forderIds[item] = true;
              // this.$set(this.forderIds, item, true);
            }
          })
          this.selected = false;
        }
        this.$nextTick(() => {
          this.huizong();
        })
      },
      delFile: function (name, id) {
        let that = this;
        $.confirm('确定要删除？', function () {
          that.axios({
            method: 'post',
            url: '/prod-api/common/delete',
            params: {id: id}
          });
          that.fileids = that.fileids.filter(item => {
            return item != id;
          });
          that.filenames = that.filenames.filter(item => {
            return item != name;
          })
        })
      },
      setFile: function (file) {
        this.filenames.push(file.name);
        this.fileids.push(file.id);
      },
      getSupplier: function () {
        this.axios({
          method: 'get',
          url: `/prod-api/organization/supplier/${this.supplierId}`,
        }).then(response => {
          if (response.data.code == 200) {
            this.supplier = response.data.data;
            this.bank = this.supplier.bank;
            this.bankcode = this.supplier.bankcode;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError('系统错误');
          }
        });
      },
      getForders: function () {
        // this.forders = [{id: 98,"acceptStatus":1,"acceptform":null,"actualSettl":752.795478,"address":"","amount":"","approvalFlag":"","aqflag":"","arealand":"郭三红","arealandid":"BC6242E581664EA29E72BEC03649E1B0","bang":"","batch":"","batchcode":"","batchcodes":[],"batchid":"","batchids":[],"carcode":"SYSTEM001","cartype":"自卸订单","city":"乌兰察布市","className":"Freightorder","code":"FO22112","condition":"","contractid":"EA2EC11BD76F4B748E502D1FBB015E8C","count":"","country":"四子王旗","createtime":"2022-11-01","damount":"","deductRateByCheck":7.33,"deductRateByHand":"","deductrate":"","deducttype":1,"deducttypeName":"","departid":"12BC95375FB84CCBAF2C24396D778002","departids":[],"department":"传统业务部-华北","depguid":"","depname":"","dictkey":"","discountrate":3,"distance":"","drivername":"DRIVER","driverphone":"TEL001","flag":"","flowid":"24","fromsrguid":"","guid":"60314DF424644F8A9D3869E3AAD5AFCD","guids":[],"harvest":"2","hrweight":18.23,"hweight":18.23,"isdiscount":2,"isdiscountName":"","lastupdate":"2022-11-08","latitude":"","longitude":"","netWeight":18.23,"nodes":[],"nostats":[],"operator":"张福","operatorid":"DCF98EC134A54820A1C5E951FF453B83","ordercode":"","organizationid":"69a1adb74d9b4f0a8367e34db7c02ef8","orgid":"","orgname":"","payCarNum":"","payMoney":"","paystats":[],"paystatus":2,"paystatusname":"","pkgCount":"","pkgwgh":0,"pkgwght":"","plantID":"","plantor":"郭三红","plantorid":"2489BFEA6BF7428F94B3515A19AE8559","plantorphone":"15947131785","price":812.34,"productinfoid":"03949BC1F53E45E896B97B37117EE873","provence":"内蒙古","qamainid":"","qamaintype":"","qaname":"","qatype":"1","ratend":7.33,"realName":"","refuseFlag":1,"remark":"生成采购订单","rweight":"","scan":"","schedul":"","search":"","sendType":"","setlwgtype":"2","settlement":13723.46,"soilchkrate":"","specification":"淀粉薯","specificationid":"","spguid":"7A328B16D0874B2FAB42F463376C38DC","spotcheckrate":"","stats":[],"status":35,"statusArr":[],"statusname":"","storehouse":"","storehousecode":"","storeroom":"OEM亿茗库","storeroomcode":"023","street":"东八号乡坡底村亿茗公司院内","strguid":"9AD1EB49B74647C38D682563518267DE","strguids":[],"sumCarNum":"","telphone":"","unitPrice":"","unloadtime":"","unpaidCount":"","unpaidMoney":"","unpaidPayCarNum":"","unpaidSettlement":"","unpaidWeight":"","unprocd_amount":"","unqualifiedchkrate":"","userType":"","variety":"中加二号","weight":18.23,"wghtperpkg":1},
        //   {id: 99,"acceptStatus":1,"acceptform":null,"actualSettl":752.795478,"address":"","amount":"","approvalFlag":"","aqflag":"","arealand":"郭三红","arealandid":"BC6242E581664EA29E72BEC03649E1B0","bang":"","batch":"","batchcode":"","batchcodes":[],"batchid":"","batchids":[],"carcode":"SYSTEM001","cartype":"自卸订单","city":"乌兰察布市","className":"Freightorder","code":"FO22112","condition":"","contractid":"EA2EC11BD76F4B748E502D1FBB015E8C","count":"","country":"四子王旗","createtime":"2022-11-01","damount":"","deductRateByCheck":7.33,"deductRateByHand":"","deductrate":"","deducttype":1,"deducttypeName":"","departid":"12BC95375FB84CCBAF2C24396D778002","departids":[],"department":"传统业务部-华北","depguid":"","depname":"","dictkey":"","discountrate":3,"distance":"","drivername":"DRIVER","driverphone":"TEL001","flag":"","flowid":"24","fromsrguid":"","guid":"60314DF424644F8A9D3869E3AAD5AFCD","guids":[],"harvest":"2","hrweight":18.23,"hweight":18.23,"isdiscount":2,"isdiscountName":"","lastupdate":"2022-11-08","latitude":"","longitude":"","netWeight":18.23,"nodes":[],"nostats":[],"operator":"张福","operatorid":"DCF98EC134A54820A1C5E951FF453B83","ordercode":"","organizationid":"69a1adb74d9b4f0a8367e34db7c02ef8","orgid":"","orgname":"","payCarNum":"","payMoney":"","paystats":[],"paystatus":2,"paystatusname":"","pkgCount":"","pkgwgh":0,"pkgwght":"","plantID":"","plantor":"郭三红","plantorid":"2489BFEA6BF7428F94B3515A19AE8559","plantorphone":"15947131785","price":812.34,"productinfoid":"03949BC1F53E45E896B97B37117EE873","provence":"内蒙古","qamainid":"","qamaintype":"","qaname":"","qatype":"1","ratend":7.33,"realName":"","refuseFlag":1,"remark":"生成采购订单","rweight":"","scan":"","schedul":"","search":"","sendType":"","setlwgtype":"2","settlement":13724,"soilchkrate":"","specification":"淀粉薯","specificationid":"","spguid":"7A328B16D0874B2FAB42F463376C38DC","spotcheckrate":"","stats":[],"status":35,"statusArr":[],"statusname":"","storehouse":"","storehousecode":"","storeroom":"OEM亿茗库","storeroomcode":"023","street":"东八号乡坡底村亿茗公司院内","strguid":"9AD1EB49B74647C38D682563518267DE","strguids":[],"sumCarNum":"","telphone":"","unitPrice":"","unloadtime":"","unpaidCount":"","unpaidMoney":"","unpaidPayCarNum":"","unpaidSettlement":"","unpaidWeight":"","unprocd_amount":"","unqualifiedchkrate":"","userType":"","variety":"中加二号","weight":18.23,"wghtperpkg":1}];
        // this.forders.forEach((item, index) => {
        //   this.$set(this.forderIds, 'order' + index, item.id);
        // })
        // this.$nextTick(() => {
        //   this.huizong();
        // })
        // return;
        this.axios({
          method: 'get',
          url: `/prod-api/pay/payinfo/getUnPayPurchasebills`,
          params: {orgId: this.orgId, supplierId: this.supplierId}
        }).then(response => {
          if (response.data.code == 200) {
            this.forders = response.data.data;
            this.forders.forEach((item, index) => {
              this.$set(this.forderIds, 'order' + index, item.id);
            })
            this.$nextTick(() => {
              this.huizong();
            })
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
              //不不设置提示
            } else {
              this.toastError('系统错误');
            }
          });
      },
      //提交表单数据
      postForm: function () {
        let that = this;
        //表单校验
        if (!this.totalGuids) {
          this.toastText('请选择采购订单!')
          return false;
        }
        if (!this.payAmount) {
          this.toastText('申请金额不能为空!')
          return false;
        }
        if (this.payAmount > this.amount) {
          this.toastText('支付金额不能大于结算金额!')
          return false;
        }
        if (!this.bank) {
          this.toastText('开户行不能为空!')
          return false;
        }
        if (!this.bankcode) {
          this.toastText('银行账号不能为空!')
          return false;
        }
        $.confirm("确定要发起付款？", function() {
          //防止重复提交
          $('.subbtn').attr("disabled",true).css("pointer-events","none");
          //显示提交状态
          $.showLoading("正在提交");
          let postData = {
            flowid: that.flowid,
            businessType: 2, //1采收 2采购
            freightorderIds: that.totalGuids,
            bank: that.bank,
            bankcode: that.bankcode,
            remark: that.opinion,
            fileIds: that.fileids.join(','),
            applyType: 1,
            applyAmount: that.payAmount
          }
          that.axios({
            method: 'post',
            url: `/prod-api/pay/payinfo/save?fileIds=${postData.fileIds}&opinion=${postData.remark}`,
            data: postData
          }).then(response => {
            //恢复提交按钮可点击
            $('.subbtn').attr('disabled', false).css("pointer-events","auto");
            //关闭提交状态
            $.hideLoading();
            if (response.data.code == 200) {
              that.toastSuccess("结算成功");
              that.$router.push({path: '/purchase2/bill/list'});
            } else {
              that.toastError('系统错误');
            }
          }).catch(function (error) {
            //恢复提交按钮可点击
            $('.subbtn').attr('disabled', false).css("pointer-events","auto");
            //关闭提交状态
            $.hideLoading();
            that.toastError('系统错误');
          });
        })
      }
    }
  }
</script>
